package com.charm.information.constract.presenter

import com.charm.codes.lifecycle.Live
import com.charm.codes.mvp.presenter.BaseMvpPresenter
import com.charm.information.api.InformationServiceManager
import com.charm.information.constract.EastHeadLineView
import com.charm.information.entity.EastItemEntity
import io.reactivex.Observer
import io.reactivex.android.schedulers.AndroidSchedulers
import io.reactivex.disposables.Disposable
import io.reactivex.schedulers.Schedulers

/**
 * Created by tools on 2018/1/11.
 */
class EastHeadLinePresenter : BaseMvpPresenter<EastHeadLineView>() {

    fun eastHeadLineList(page: Int, catid: String) {
        var apiKey ="MqtghNHt2aLFogjaxX0uL0sx5SncuWTnR4cqc7UgcUoYU0g7v5zQjVZOjbCo4BAu"
        InformationServiceManager.informationService()!!.eastHeadLine(apiKey, catid)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .compose(Live.bindLifecycle(mvpView))
                .filter { t -> t.data != null }
                .map { t -> t.data!! }
                .subscribe(object : Observer<List<EastItemEntity>> {
                    override fun onError(e: Throwable) {

                    }

                    override fun onSubscribe(d: Disposable) {

                    }

                    override fun onComplete() {
                        mvpView.netComplete()
                    }

                    override fun onNext(t: List<EastItemEntity>) {
                        mvpView.eastHeadLineList(t)
                    }


                })

    }
}